﻿using System;
using Microsoft.AspNetCore.Mvc;

namespace PageOffice6_Net_Core.Controllers.WordDataTag2
{
    public class WordDataTag2Controller : Controller
    {
        public IActionResult Word()
        {
            PageOfficeNetCore.PageOfficeCtrl poCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);

            //定义WordDocument对象
            PageOfficeNetCore.Word.WordDocumentWriter doc = new PageOfficeNetCore.Word.WordDocumentWriter();
            //定义DataTag对象
            PageOfficeNetCore.Word.DataTagWriter deptTag = doc.OpenDataTag("{部门名}");
            deptTag.Value = "技术";

            PageOfficeNetCore.Word.DataTagWriter userTag = doc.OpenDataTag("{姓名}");
            userTag.Value = "李志";

            PageOfficeNetCore.Word.DataTagWriter dateTag = doc.OpenDataTag("【时间】");
            dateTag.Value = DateTime.Now.ToString("yyyy-MM-dd");

            poCtrl.SetWriter(doc);
            //打开Word文档
            poCtrl.WebOpen("doc/test2.doc", PageOfficeNetCore.OpenModeType.docNormalEdit, "tom");
            ViewBag.poCtrl = poCtrl.GetHtml();
            return View();
        }
    }
}